#include <iostream>
#include <mlt++/Mlt.h>

int main(int argc, char** argv){
	std::cerr << "argc : " << argc << std::endl;
	if(argc != 2){
		std::cerr << "You have to enter one video file name argument : " << std::endl;
		return 0;
	}
	Mlt::Factory::init(NULL);
	Mlt::Profile *m_profile = new Mlt::Profile ("square_ntsc_wide");
	//Mlt::Producer *producer = new Mlt::Producer (*m_profile, "vamp.mp4");
	Mlt::Producer *producer = new Mlt::Producer (*m_profile, argv[1]);
	double fps = producer->get_fps();
	std::cerr << "fps : " << fps << std::endl;

	Mlt::Frame *frame;

	int timeMediaInSec = 15;
	int nFrame = timeMediaInSec*fps; //TODO fin how to get the good number of frame

	int width = 200;
	int height = 200; //the higher are those 2 data, the higher is the precision of the waveform

	for(int i=0; i<nFrame; i++){
		frame = producer->get_frame(i);
		unsigned char* waves = frame->get_waveform(width, height);
		int mean = 0;
		for(int j=0; j<width*height; j++){
			mean += int(waves[j]);
		}
		mean /= width*height;
		std::cout << mean << std::endl;
	}
	std::cerr << "Finished" << std::endl;
	return 0;
}

